import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

// 图标
/*
* 增加isWeb选项，解决web模式下 图标小于12px的问题
* */
class TEIcon extends StatelessWidget {
  const TEIcon(this.icon, {Key key, this.size, this.color, this.semanticLabel, this.textDirection}) : super(key: key);

  final IconData icon;

  final double size;

  final Color color;

  final String semanticLabel;

  final TextDirection textDirection;

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    if (kIsWeb && size < 12) {
      return Transform.scale(
        // origin: Offset(0, -size),
        scale: size / 12,
        child: Icon(
          icon,
          key: key,
          size: 12,
          color: color,
          semanticLabel: semanticLabel,
          textDirection: textDirection,
        ),
      );
    }
    return Icon(
      icon,
      key: key,
      size: size,
      color: color,
      semanticLabel: semanticLabel,
      textDirection: textDirection,
    );
  }
}

class IconPage extends StatefulWidget {
  IconPage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _IconPageState createState() => _IconPageState();
}

class _IconPageState extends State<IconPage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Container(
          color: Colors.green,
          child: TEIcon(
            Icons.keyboard_arrow_down_sharp,
            size: 8,
            color: Colors.redAccent,
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
